<div id="locationSelDlg" class="easyui-dialog"
		title="Select Location..."
		style="width: 400px; height: 300px; padding: 10px"
		data-options="toolbar: '#locationSel-toolbar',
			buttons: '#locationSel-buttons',
			closed: true">		
			<ul id="locationSelTree" class="easyui-tree" style="width: 200px;" data-options="url:'loadLocations.htm'"></ul>		
	</div>
	<div id="addNewLocationDlg" class="easyui-dialog"
		title="Add New Location..."
		style="width: 400px; height: 300px; padding: 10px"
		data-options="buttons: '#addLocation-buttons',
			closed: true">
		<table>
			<tr>
				<td>Name:</td>
				<td><input class="easyui-validatebox" type="text"
					name="newLocationName" id="newLocationName" style="width: 250px;"
					 data-options="required:true"></input></td>
			</tr>
			<tr>
				<td>Street</td>
				<td><input class="easyui-validatebox" type="text"
					name="newLocationStreet1" id="newLocationStreet1" style="width: 250px;"></input>					 					 
				</td>
			</tr>
			<tr>
				<td style="vetical-align:top;"></td>
				<td><input class="easyui-validatebox" type="text"
					name="newLocationStreet2" id="newLocationStreet2" style="width: 250px;"></input>				 
				</td>
			</tr>
			<tr>
				<td>City:</td>
				<td><input class="easyui-validatebox" type="text"
					name="newLocationCity" id="newLocationCity" style="width: 250px;"></input>
				</td>
			</tr>
			<tr>
				<td>State/Province:</td>
				<td><input class="easyui-validatebox" type="text"
					name="newLocationState" id="newLocationState" style="width: 250px;"></input>
				</td>
			</tr>
			<tr>
				<td>Postal Code:</td>
				<td><input class="easyui-validatebox" type="text"
					name="newLocationPostalCode" id="newLocationPostalCode" style="width: 250px;"></input>
				</td>
			</tr>
			<tr>
				<td>Country:</td>
				<td><input id="newLocationCountryList" class="easyui-combobox" style="width: 60px;"
					data-options="valueField:'value',textField:'text',url:'getCountryList.htm'"/>
				</td>
			</tr>			
		</table>
	</div>

	<div id="locationSel-toolbar" style="padding: 2px 0">
		<table cellpadding="0" cellspacing="0" style="width: 100%">
			<tr>
				<td style="padding-left: 2px"><a id="addLocation"
					href="javascript:void(0)" class="easyui-linkbutton"
					data-options="iconCls:'icon-add',plain:true">Add New</a> <a
					href="javascript:void(0)" class="easyui-linkbutton"
					data-options="iconCls:'icon-help',plain:true">Help</a></td>
			</tr>
		</table>
	</div>

	<script type="text/javascript">
		function addNewLocation() {			
				$("#locationSelDlg").dialog("close");				
				$("#addNewLocationDlg").dialog("open");			
		}

		function selectLocationValue() {			
			var node = $('#locationSelTree').tree('getSelected');
			if (node) {
				$("#location").val(node.text);
				$("#hidlocation").val(node.id);				
				$('#locationSelDlg').dialog('close');
				enableDisableValidation('location','hidlocation');
			}
		}
		function selectLocation() {			
			$('#locationSelDlg').dialog('open');
		}
		
		function saveNewLocation() {
			
			var data = {
				name : $("#newLocationName").val()				
			};
			if($("#newLocationStreet1").val()!="")
				data["street1"]=$("#newLocationStreet1").val();
			if($("#newLocationStreet2").val()!="")
				data["street2"]=$("#newLocationStreet2").val();
			if($("#newLocationCity").val()!="")
				data["city"]=$("#newLocationCity").val();
			if($("#newLocationState").val()!="")
				data["state"]=$("#newLocationState").val();
			if($("#newLocationPostalCode").val()!="")
				data["postalCode"]=$("#newLocationPostalCode").val();
			var country=$("#newLocationCountryList").combobox('getValue');
			
			if(country!="")
				data["country"]=country;
			
			
			$.postJSON("addNewLocation.htm", data, function(result) {
				if (result.success) {
					$("#location").val(result.text);
					$("#hidlocation").val(result.id);					
					$("#addNewLocationDlg").dialog("close");
					enableDisableValidation('location','hidlocation');
				} else {
					showMessager("Exception", result.message);
				}
			}, function(xhr, ajaxOptions, thrownError) {
				showMessager("Exception", thrownError);
			});

		}
		function showMessager(title, message) {
			$.messager.show({
				title : title,
				msg : message,
				showType : 'show'
			});
		}
		/*$(document).ready(function(){
			$.getJSON('getCountryList.htm',function(data){
				$.each(data,function(ind,obj){
				
				});
			});
		});*/
		$("#addLocation").click(addNewLocation);
		$("#locationSel").click(selectLocation);
		
		
	</script>
	<div id="locationSel-buttons">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			onclick="selectLocationValue()">Select</a> <a href="javascript:void(0)"
			class="easyui-linkbutton"
			onclick="javascript:$('#locationSelDlg').dialog('close')">Close</a>
	</div>

	<div id="addLocation-buttons">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			id="saveNewLocationBtn" onclick="saveNewLocation();">Save</a> <a href="javascript:void(0)"
			class="easyui-linkbutton"
			onclick="javascript:$('#addNewLocationDlg').dialog('close')">Close</a>
	</div>